package com.xy.controller;

import com.xy.entity.Author;
import com.xy.entity.Book;
import com.xy.repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
//这个只是为了方便导入测试数据的控制器
public class MainController {
    @Autowired
    private BookRepository bookRepository;
    @RequestMapping("/initData")
    @ResponseBody
    public Iterable<Book> index(){
        //导入测试数据
        for(int i=1;i<10;++i){
            Book book=new Book();
            Author author=new Author();
            author.setName("ar "+i);
            author.setAge(i*20);

            book.setName("bk "+i);
            book.setPrice(i*15);
            book.setAuthor(author);
            bookRepository.save(book);
        }
        return bookRepository.findAll();
    }
}